<template>
  <div class="device-container">
    <div class="top-view">
      <div class="title-view">
        <div class="device-title"></div>
      </div>
      <div class="loc-view">
        <img style="width: 14px;height: 17px;" src="@/assets/images/current-img.png" alt="">
        <img style="width: 189px;height: 14px; margin-left: 5px;" src="@/assets/images/current.png" alt="">
      </div>
    </div>
    
    <el-form class="search-view" :model="queryParams" ref="queryRef" :inline="true"
      label-width="68px">
      <el-form-item label="设备名称" prop="sbmc">
        <el-input v-model="queryParams.sbmc" placeholder="请输入设备名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="设备型号" prop="sbxh">
        <el-input v-model="queryParams.sbxh" placeholder="请输入设备型号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="设备状态" prop="sbzt">
        <el-input v-model="queryParams.sbzt" placeholder="请输入设备状态" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button @click="handleAdd" v-hasPermi="['system:sbda:add']">新增设备</el-button>
      </el-form-item>
    </el-form>
    <el-table class="table-view" :data="sbdaList"
      :style="{ backgroundColor: 'rgba(0, 0, 0, 0)'}" :header-row-style="headerRowStyle"
      :header-cell-style="headerCellStyle" :row-style="rowStyle" :cell-style="cellStyle">
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="设备编号" align="center" prop="sbbh" />
      <el-table-column label="设备名称" align="center" prop="sbmc" />
      <el-table-column label="设备位置" align="center" prop="sbwz" />
      <el-table-column label="所属实验室" align="center" prop="sys" />
      <el-table-column label="品牌名称" align="center" prop="pp" />
      <el-table-column label="设备型号" align="center" prop="sbxh" />
      <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="handleDetail(scope.row)"
            v-hasPermi="['system:sbda:remove']">详情</el-button>
            <el-button link type="primary" @click="handleDelete(scope.row)"
            v-hasPermi="['system:sbda:remove']">删除</el-button>
          <el-button link type="primary" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:sbda:edit']">修改</el-button>
            <!-- <el-button link type="primary" @click="handleChange(scope.row)"
            v-hasPermi="['system:sbda:edit']">维修</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination class="page-view" v-show="total > 0" :small="true" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
    <AddEquipment v-model:open="open" :params="form" :title="title" @finsih="handleQuery"></AddEquipment>  
    <EquipmentDetail v-model:open="openDetail" :params="form" @finsih="handleQuery"></EquipmentDetail> 
     
  </div>
  
</template>

<script setup>
import { listSbda, delSbda } from "@/api/system/sbda";
import AddEquipment from "./components/addEquipment.vue";
import EquipmentDetail from "./components/equipmentDetail.vue";
import { ElMessage , ElMessageBox} from "element-plus";
const { proxy } = getCurrentInstance();

const sbdaList = ref([]);
const open = ref(false);
const openDetail = ref(false);
const loading = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    SBMC: null,
    SYS: null,
    SBXH: null,
    SBWZ: null,
    SBZT: null,
    FZR: null,
    FRZDH: null,
    PP: null,
    SBCS: null,
    CCRQ: null,
    BBSJ: null
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询设备档案列表 */
function getList() {
  loading.value = true;
  listSbda(queryParams.value).then(response => {
    sbdaList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
getList();
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 新增按钮操作 */
function handleAdd() {
  open.value = true;
  form.value = null 
  title.value = "添加设备档案";
}
/** 详情按钮操作 */
function handleDetail(row) {
    form.value = row;
    openDetail.value = true;
}
/** 修改按钮操作 */
function handleUpdate(row) {
  form.value = row;
  open.value = true;
  title.value = "修改设备档案";
}
/** 删除按钮操作 */
function handleDelete(row) {
  const _SBBHs = row.sbbh
  ElMessageBox.confirm('是否确认删除设备档案编号为"' + _SBBHs + '"的数据项？').then(function () {
    return delSbda(_SBBHs);
  }).then(() => {
    getList();
    ElMessage.success("删除成功");
  }).catch(() => { });
}
// 修改table央视
function headerRowStyle({ row, rowIndex }) {
  return {
    backgroundColor: 'rgba(0, 0, 0, 0)',
  }
}
function headerCellStyle({ row, column, rowIndex, columnIndex }) {
  return {
    backgroundColor: 'rgba(3, 16, 69, 0.6) !important',
    borderBottom: 'none',
    color: '#76b4f4 !important'
  }
}
function rowStyle({ row, rowIndex }) {
  if (rowIndex%2 === 0) {
    return {
      backgroundColor: 'rgba(0, 0, 0, 0)',
      border: 'none'
    }
  } else {
    return {
      backgroundColor: 'rgba(3, 16, 69, 0.6)',
      border: 'none'
    }
  }
}
function cellStyle({ row, column, rowIndex, columnIndex }) {
  return {
    backgroundColor: 'rgba(0, 0, 0, 0)',
    border: 'none',
    color: '#a0caf5 !important'
  }
}
</script>
<style lang="scss" scoped>
@import './index.scss'
</style>
